<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class UserPostRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        //false关闭  true 开启
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
      public function rules()
        {
            return [
                //定义规则
                'username' => 'required|unique:users|min:6|max:50',//用户规则
                'password' => 'required|min:6|max:50',//密码规则
                'repassword' => 'required|same:password',//确认密码规则
                'email' => 'required|email|unique:users',//邮箱规则
                'phone' => 'required|numeric|digits_between:11,11',//手机号规则
                    ];
        }
        //自定义错误返回
        public function messages()
        {
            return [
                //错误信息
                'username.required'=>'用户名不能为空',
                'password.required'=>'密码不能为空',
                'repassword.required'=>'确认密码不能为空',
                'repassword.same'=>'两次密码不一致',
                'email.required'=>'邮箱不能为空',
                'email.email'=>'邮箱格式不对',
                'email.unique'=>'邮箱已被注册',
                'phone.required'=>'手机号不能为空',
                'phone.numeric' => '手机号格式不正确',
                'phone.digits_between' => '请填写正确的手机号',
                'username.unique'=>'该用户已被注册',
                'username.min' => '用户名过短',
                'username.max' => '用户名过长',
                'password.min' => '密码过短',
                'password.max' => '密码过长',
            ];
        }
}
